load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_python//python:py_library.bzl", "py_library")

package(default_visibility = ["//:__subpackages__"])

# Python library for icebox modules
py_library(
    name = "icebox_lib",
    srcs = [
        "icebox.py",
        "iceboxdb.py",
    ],
    imports = ["."],
)

# Python binary for chipdb generation
py_binary(
    name = "icebox_chipdb",
    srcs = ["icebox_chipdb.py"],
    imports = ["."],
    main = "icebox_chipdb.py",
    deps = [":icebox_lib"],
)

# Python tools as libraries
py_library(
    name = "icebox_tools_lib",
    srcs = [
        "icebox_asc2hlc.py",
        "icebox_colbuf.py",
        "icebox_diff.py",
        "icebox_explain.py",
        "icebox_hlc2asc.py",
        "icebox_hlcsort.py",
        "icebox_html.py",
        "icebox_maps.py",
        "icebox_stat.py",
        "icebox_vlog.py",
    ],
    imports = ["."],
    deps = [":icebox_lib"],
)

# Chipdb generation rules
genrule(
    name = "chipdb_384",
    outs = ["chipdb-384.txt"],
    cmd = "$(execpath :icebox_chipdb) -3 > $@",
    cmd_bat = "$(execpath :icebox_chipdb) -3 > $@",
    tools = [":icebox_chipdb"],
)

genrule(
    name = "chipdb_1k",
    outs = ["chipdb-1k.txt"],
    cmd = "$(execpath :icebox_chipdb) > $@",
    cmd_bat = "$(execpath :icebox_chipdb) > $@",
    tools = [":icebox_chipdb"],
)

genrule(
    name = "chipdb_8k",
    outs = ["chipdb-8k.txt"],
    cmd = "$(execpath :icebox_chipdb) -8 > $@",
    cmd_bat = "$(execpath :icebox_chipdb) -8 > $@",
    tools = [":icebox_chipdb"],
)

genrule(
    name = "chipdb_5k",
    outs = ["chipdb-5k.txt"],
    cmd = "$(execpath :icebox_chipdb) -5 > $@",
    cmd_bat = "$(execpath :icebox_chipdb) -5 > $@",
    tools = [":icebox_chipdb"],
)

genrule(
    name = "chipdb_u4k",
    outs = ["chipdb-u4k.txt"],
    cmd = "$(execpath :icebox_chipdb) -u > $@",
    cmd_bat = "$(execpath :icebox_chipdb) -u > $@",
    tools = [":icebox_chipdb"],
)

genrule(
    name = "chipdb_lm4k",
    outs = ["chipdb-lm4k.txt"],
    cmd = "$(execpath :icebox_chipdb) -4 > $@",
    cmd_bat = "$(execpath :icebox_chipdb) -4 > $@",
    tools = [":icebox_chipdb"],
)

filegroup(
    name = "chipdb_files",
    srcs = [
        ":chipdb_1k",
        ":chipdb_384",
        ":chipdb_5k",
        ":chipdb_8k",
        ":chipdb_lm4k",
        ":chipdb_u4k",
    ],
)
